import { RouteRecordRaw } from 'vue-router'

const allRoutes = import.meta.globEager('./modules/*.js')

// 导出原始路由数据，用于面包屑导航
export let routeList: RouteRecordRaw[] = [];
for(const key in allRoutes){
    routeList.push(allRoutes[key].default)
}

// 子路由扁平化
let flattenRouteList: RouteRecordRaw[] = [];
routeList.forEach((listItem) => {
    if (listItem.children && listItem.children.length > 0) {
        flattenRouteList.push(...listItem.children)
    }
})
const routes = [
  {
      path: '/',
      name: 'Home',
      component: () => import('@p/home/index.vue'),
      children: [
          {
              path: '/',
              name: 'index',
              component: () => import('@p/index/index.vue')
          },
          ...flattenRouteList
      ]
  }
]
export default routes;